package com.atomscat.lottery.config.db;

import com.atomscat.lottery.entity.db.UserEntity;
import com.atomscat.lottery.service.UserEntityService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.data.domain.AuditorAware;
import org.springframework.data.domain.ReactiveAuditorAware;
import org.springframework.security.core.context.ReactiveSecurityContextHolder;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;

import java.util.Optional;

@Slf4j
@Component("auditorProvider")
@RequiredArgsConstructor
public class JpaAuditorAwareImpl implements AuditorAware<UserEntity> {

//    private final UserEntityService userEntityService;

    @Override
    public Optional<UserEntity> getCurrentAuditor() {
//        User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        // todo get redis cache
//        UserEntity userEntity = userEntityService.findByLoginId(user.getUsername());
//        return Optional.of(userEntity);
        UserEntity userEntity = new UserEntity();
        userEntity.setId(-1L);
        return Optional.of(userEntity);
    }
}
